package com.kele.base.model.response;

import com.kele.base.common.constant.ResponseResultCodeEnum;

import java.io.Serializable;

/**
 * @Description: 返回结果类
 * @Author: Kele
 * @CreateDate: 2023/3/26 19:31
 * @Version:
 */
public class ResponseResult implements Serializable {
    // 状态码
    private int code;
    // 错误信息
    private String msg;
    // 返回结果
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     *@param
     *@desc 自定义code，message，也可以在ResponseResultCodeEnum中提前规定
     */
    public static  ResponseResult custom(int code, String msg, Object data) {
        ResponseResult ResponseResult = new ResponseResult();
        ResponseResult.setCode(code);
        ResponseResult.setMsg(msg);
        ResponseResult.setData(data);
        return ResponseResult;
    }

    /**
     *@param
     *@desc 自定义code，message，也可以在ResponseResultCodeEnum中提前规定
     */
    public static ResponseResult custom(int code, String msg) {
        ResponseResult ResponseResult = new ResponseResult();
        ResponseResult.setCode(code);
        ResponseResult.setMsg(msg);
        return ResponseResult;
    }

    public static  ResponseResult success(Object data, String msg) {
        ResponseResult ResponseResult = new ResponseResult();
        ResponseResult.setCode(ResponseResultCodeEnum.SUCCESS.getCode());
        ResponseResult.setMsg(msg == null ? ResponseResultCodeEnum.SUCCESS.getMessage() : msg);
        ResponseResult.setData(data);
        return ResponseResult;
    }

    public static  ResponseResult success(Object data) {
        ResponseResult ResponseResult = new ResponseResult();
        ResponseResult.setCode(ResponseResultCodeEnum.SUCCESS.getCode());
        ResponseResult.setMsg(ResponseResultCodeEnum.SUCCESS.getMessage());
        ResponseResult.setData(data);
        return ResponseResult;
    }

    public static ResponseResult success() {
        ResponseResult ResponseResult = new ResponseResult();
        ResponseResult.setCode(ResponseResultCodeEnum.SUCCESS.getCode());
        ResponseResult.setMsg(ResponseResultCodeEnum.SUCCESS.getMessage());
        return ResponseResult;
    }

    public static  ResponseResult fail(String msg, Object data) {
        ResponseResult ResponseResult = new ResponseResult();
        ResponseResult.setCode(ResponseResultCodeEnum.FAIL.getCode());
        ResponseResult.setMsg(msg == null ? ResponseResultCodeEnum.FAIL.getMessage() : msg);
        ResponseResult.setData(data);
        return ResponseResult;
    }

    public static ResponseResult fail(String msg) {
        ResponseResult ResponseResult = new ResponseResult();
        ResponseResult.setCode(ResponseResultCodeEnum.FAIL.getCode());
        ResponseResult.setMsg(msg == null ? ResponseResultCodeEnum.FAIL.getMessage() : msg);
        return ResponseResult;
    }

}
